﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Common;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace LambdaToSql.DbHelper
{
    internal class Factory
    {
        /// <summary>
        /// 数据库上下文对象
        /// </summary>
        internal LambdaToSql.EntityModel.DbContext Context { get; set; }

        /// <summary>
        /// 数据库初始化接口 推荐
        /// </summary>
        public IDBhelper IDBhelper
        {
            get
            {
                switch (this.Context.SqlType)
                {
                    //case LambdaToSql.EntityModel.SqlType.MySql:
                    //case LambdaToSql.EntityModel.SqlType.Oracle:
                    //case LambdaToSql.EntityModel.SqlType.Odbc:
                    //    {
                    //        return null;
                    //    }
                    case LambdaToSql.EntityModel.SqlType.SQLite:
                        {
                            var client = new SqLite() { Context = this.Context };
                            return client;
                        }
                    case LambdaToSql.EntityModel.SqlType.MsSqlServer:
                    default:
                        {
                            var client = new MsSqlServer() { Context = this.Context };
                            return client;
                        }
                }

                //var client = new MsSqlServer() { Context = this.Context };
                //return client;
            }
        }

        /// <summary>
        /// 老方法 初始化 原始用法不推荐 
        /// <para>推荐使用属性 IDBhelper</para>
        /// </summary>
        /// <returns></returns>
        public IDBhelper Init()
        {
            return this.IDBhelper;
        }
    }
}
